package com.cykj.service.Impl;

import com.cykj.dto.ResponseDto;
import com.cykj.mapper.BillMapper;
import com.cykj.pojo.PsBill;
import com.cykj.service.BillService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: Psychology
 * @BelongsPackage: com.cykj.service.Impl
 * @Author: 小林
 * @CreateTime: 2025-02-15 16:43
 * @Description: 账单表
 * @Version: 1.0
 */
@Service
public class BillServiceImpl implements BillService {
    @Autowired
    private BillMapper billMapper;

    /**
     * 插入记录
     * @param psBill
     * @return
     */
    @Override
    public ResponseDto addRecord(PsBill psBill) {
        final int i = billMapper.addRecord(psBill);
        if(i>0){
            return ResponseDto.success("新增成功");
        }
        return ResponseDto.error("新增失败");
    }

    /**
     * 获取全部
     * @param psBill
     * @return
     */
    @Override
    public ResponseDto getAll(PsBill psBill) {
        PageHelper.startPage(psBill.getPageNum(),psBill.getPageSize());
        final List<PsBill> all = billMapper.getAll(psBill);
        PageInfo<PsBill> pageInfo = new PageInfo<>(all);
        return all!=null?ResponseDto.success(pageInfo):ResponseDto.error("查询失败！");
    }
}

